package com.cfk.controller;

import cfk.pojo.order.CustQueryReq;
import cfk.pojo.order.CustQueryResp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.env.Environment;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @author baohuajie
 * @description: test
 * @date 2020/11/135:36 PM
 */
@RestController
public class HelloController {
    private final Logger log = LoggerFactory.getLogger(HelloController.class);
    @Autowired
    private Environment environment;
    @RequestMapping(value = "/hello")
    public String hello(){
        log.info("=========当前端口号:{}=========");

        return "hello world";
    }

    @RequestMapping(value = "/hystrixQuery")
    public CustQueryResp hystrixQuery(@RequestBody CustQueryReq req){
        log.info("=========连接线程:{}=========", Thread.currentThread().getName());
        log.info("=========当前端口号:{}=========", environment.getProperty("server.port"));
        CustQueryResp resp = new CustQueryResp();
        resp.setCustId(req.getCustId());
        resp.setCustName(req.getCustId() + "name");
        return resp;
    }

    @RequestMapping(value = "/hystrixQueryBatch")
    public List<CustQueryResp> hystrixQueryBatch(@RequestBody CustQueryReq req){
        log.info("=========连接线程:{}=========", Thread.currentThread().getName());
        List<CustQueryResp> resultList = new ArrayList<>();
        for (int i = 0; i <= 1000; i++) {
            CustQueryResp resp = new CustQueryResp();
            resp.setCustId(req.getCustId() + ":" + String.valueOf(i));
            resp.setCustName(req.getCustId() + "name");
            resultList.add(resp);
        }
        return resultList;
    }

    @RequestMapping(value = "/hystrixObservable")
    public CustQueryResp hystrixObservable(@RequestBody CustQueryReq req){
        log.info("=========连接线程:{}=========", Thread.currentThread().getName());
        CustQueryResp resp = new CustQueryResp();
        resp.setCustId(req.getCustId());
        resp.setCustName(req.getCustId() + "hystrixObservable");
        return resp;
    }
}
